﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Basic;
using Interface;
using GameEnum;

namespace Client
{
    public class UIWindowLogin : UIWindow
    {
        /// <summary>
        /// 界面唯一标识
        /// </summary>
        public const string UIKEY = "UIWindowLogin";

        private GameObject m_Setting;
        private InputField m_Account;
        private InputField m_Password;
        private GameObject m_Login;

        public UIWindowLogin() : base(UIKEY)
        {
        }

        protected override void OnVisualLoaded()
        {
            base.OnVisualLoaded();

            if (!InUsing)
            {
                return;
            }

            m_Setting = Visual.GetGameObjectAtChild("Animation/TopLeft/Setting.GO");
            m_Account = Visual.GetInputFieldAtChild("Animation/Center/Panel_Login/Account.GO");
            m_Password = Visual.GetInputFieldAtChild("Animation/Center/Panel_Login/Password.GO");
            m_Login = Visual.GetGameObjectAtChild("Animation/Center/Panel_Login/Login.GO");

            UITouchEventListener comp = null;
            comp = m_Setting.GetOrAddComponent<UITouchEventListener>();
            comp.SetClick(OnClickSetting);
            comp = m_Login.GetOrAddComponent<UITouchEventListener>();
            comp.SetClick(OnClickLogin);
        }

        protected override void DoSafeClear()
        {
            if (Visual != null)
            {
                UITouchEventListener comp = null;
                comp = m_Setting.GetOrAddComponent<UITouchEventListener>();
                comp.ClearAll();
                comp = m_Login.GetOrAddComponent<UITouchEventListener>();
                comp.ClearAll();
            }

            base.DoSafeClear();
        }

        private void OnClickSetting(GameObject go)
        {
            Log.Debug("OnClickSetting");
        }
        private void OnClickLogin(GameObject go)
        {
            Log.Debug("OnClickLogin");
            Log.Debug("Account {0}", m_Account.text);
            Log.Debug("Password {0}", m_Password.text);

            Global.GameLogicManager.EnterGameLogic(EGameLogicType.PeaceMain);
        }
    }
}
